import Vue from 'vue'
import Router from 'vue-router'

import Login from '@/views/Login.vue'
import Index from '@/views/Index.vue'
import Link from '@/views/link/Link.vue'
import Article from '@/views/article/Article.vue'
import ArticleAdd from '@/views/article/ArticleAdd.vue'
import ArticleUpd from '@/views/article/ArticleUpd.vue'

import ArticleCategory from '@/views/article/ArticleCategory.vue'
import SysUser from '@/views/user/SysUser.vue'
import Statistics from '@/views/statistics/Statistics.vue'
import Notice from '@/views/notice/Notice.vue'
import Tag from '@/views/tag/Tag.vue'
import Log from '@/views/log/Log.vue'
import Black from '@/views/black/Black.vue'
import Job from '@/views/job/Job.vue'
import Calendar from '@/views/calendar/Calendar.vue'

Vue.use(Router)

// 获取原型对象上的push函数
const originalPush = Router.prototype.push
// 修改原型对象中的push方法
Router.prototype.push = function push (location) {
    return originalPush.call(this, location).catch(err => err)
}

const routes = [{
    path: '/',
    name: 'Login',
    component: Login,
    meta: {
        title: '登录/注册'
    }

},

{
    path: '/index',
    name: 'Index',
    component: Index,
    meta: {
        title: '首页'
    },
    redirect: '/statistics',
    children: [{
        path: '/link',
        name: 'Link',
        component: Link,
        meta: {
            title: '友情链接'
        }
    },
    {
        path: '/article',
        name: 'Article',
        component: Article,
        meta: {
            title: '文章管理'
        }
    },
    {
        path: '/articleAdd',
        name: 'ArticleAdd',
        component: ArticleAdd,
        meta: {
            title: '新增文章'
        }
    },
    {
        path: '/articleUpd',
        name: 'ArticleUpd',
        component: ArticleUpd,
        meta: {
            title: '修改文章'
        }
    },
    {
        path: '/articleCategory',
        name: 'ArticleCategory',
        component: ArticleCategory,
        meta: {
            title: '文章分类'
        }
    },
    {
        path: '/sysUser',
        name: 'SysUser',
        component: SysUser,
        meta: {
            title: '系统用户'
        }
    },
    {
        path: '/statistics',
        name: 'Statistics',
        component: Statistics,
        meta: {
            title: '数据统计'
        }
    },
    {
        path: '/calendar',
        name: 'Calendar',
        component: Calendar,
        meta: {
            title: '日历'
        }
    },
    {
        path: '/notice',
        name: 'Notice',
        component: Notice,
        meta: {
            title: '通知公告'
        }
    },
    {
        path: '/log',
        name: 'Log',
        component: Log,
        meta: {
            title: '访问日志'
        }
    },
    {
        path: '/black',
        name: 'Black',
        component: Black,
        meta: {
            title: '黑名单'
        }
    },
    {
        path: '/job',
        name: 'Job',
        component: Job,
        meta: {
            title: '任务调度'
        }
    },
    {
        path: '/tag',
        name: 'Tag',
        component: Tag,
        meta: {
            title: '云标签'
        }
    }
    ]
}
]

export default new Router({
    routes: routes,
    scrollBehavior (to, from, savePosition) {
    // 如果不是查看详情路由，则页面跳转到对应的顶部
        return {
            x: 0,
            y: 0
        }
    }
})
